package com.ruoyi.web.controller.item;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.item.domain.SysGoodsAddr;
import com.ruoyi.item.service.ISysGoodsAddrService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 存放位置Controller
 * 
 * @author ruoyi
 * @date 2022-03-25
 */
@Api("存放位置Controller")
@RestController
@RequestMapping("/item/goodsaddr")
public class SysGoodsAddrController extends BaseController
{
    @Autowired
    private ISysGoodsAddrService sysGoodsAddrService;

    /**
     * 查询存放位置列表
     */
    @ApiOperation("查询存放位置列表")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:list')")
    @GetMapping("/list")
    public AjaxResult list(SysGoodsAddr sysGoodsAddr)
    {
        List<SysGoodsAddr> list = sysGoodsAddrService.selectSysGoodsAddrList(sysGoodsAddr);
        return AjaxResult.success(list);
    }

    /**
     * 导出存放位置列表
     */
    @ApiOperation("导出存放位置列表")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:export')")
    @Log(title = "存放位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGoodsAddr sysGoodsAddr)
    {
        List<SysGoodsAddr> list = sysGoodsAddrService.selectSysGoodsAddrList(sysGoodsAddr);
        ExcelUtil<SysGoodsAddr> util = new ExcelUtil<SysGoodsAddr>(SysGoodsAddr.class);
        util.exportExcel(response, list, "存放位置数据");
    }

    /**
     * 获取存放位置详细信息
     */
    @ApiOperation("获取存放位置详细信息")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(sysGoodsAddrService.selectSysGoodsAddrByDeptId(deptId));
    }

    /**
     * 新增存放位置
     */
    @ApiOperation("新增存放位置")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:add')")
    @Log(title = "存放位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGoodsAddr sysGoodsAddr)
    {
        return toAjax(sysGoodsAddrService.insertSysGoodsAddr(sysGoodsAddr));
    }

    /**
     * 修改存放位置
     */
    @ApiOperation("修改存放位置")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:edit')")
    @Log(title = "存放位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGoodsAddr sysGoodsAddr)
    {
        return toAjax(sysGoodsAddrService.updateSysGoodsAddr(sysGoodsAddr));
    }

    /**
     * 删除存放位置
     */
    @ApiOperation("删除存放位置")
    @PreAuthorize("@ss.hasPermi('item:goodsaddr:remove')")
    @Log(title = "存放位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(sysGoodsAddrService.deleteSysGoodsAddrByDeptIds(deptIds));
    }
}
